const path = require('path')
const Koa = require('koa')
const koaBody = require('koa-body')
const app = new Koa()
app.use(
  koaBody({
    multipart: true, // 支持文件上传
    formidable: {
      keepExtensions: true, // 保持文件的后缀
      maxFieldsSize: 1024 * 1024 * 100, // 文件上传大小
      uploadDir: './images', // 图片保存路径
      onFileBegin(name, file) {
        // 拼接新路径
        const newPath = path.resolve(__dirname, `images/{file.name}`)
        // 覆盖原路径
        file.path = newPath
      },
    },
  })
)
const baiduRouter = require('./route/baidu.router')
const tencentRouter = require('./route/tencent.router')
const fsRouter = require('./route/face++.router')

app.use(baiduRouter.routes())
app.use(baiduRouter.allowedMethods())
app.use(tencentRouter.routes())
app.use(tencentRouter.allowedMethods())
app.use(fsRouter.routes())
app.use(fsRouter.allowedMethods())

app.listen(3000, () => console.log('服务启动成功'))
